var prefix = ctx + "admin/menu";

$(function() {
	var options = {
		code : "menuId",
		parentCode : "parentId",
		uniqueId : "menuId",
		rootIdValue : "-1",
		expandAll : false,
		expandFirst : false,
		url : prefix + "/list",
		createUrl: prefix + "/goEditMenu",
		updateUrl: prefix + "/goEditMenu",
        removeUrl: prefix + "/{id}",
		modalName : "菜单",
		columns : [
				{
					field : 'selectItem',
					radio : true
				},
				{
					title : '菜单名称',
					field : 'name',
					width : '20%',
					formatter : function(value, row, index) {
						if ($.common.isEmpty(row.icon)) {
							return row.name;
						} else {
							return '<i class="' + row.icon
									+ '"></i> <span class="nav-label">'
									+ row.name + '</span>';
						}
					}
				},
				{
					field : 'sort',
					title : '排序',
					width : '15%',
					align : "left",
					formatter : function(value, row, index) {
						return value == null ? '-' : value
					}
				},
				{
					field : 'path',
					title : '组件路径',
					width : '15%',
					align : "left",
					formatter : function(value, row, index) {
						return $.table.tooltip(value);
					}
				},
				{
					title : '类型',
					field : 'type',
					width : '15%',
					align : "left",
					formatter : function(value, item, index) {
						if (item.type == '0') {
							return '<span class="label label-primary">菜单</span>';
						} else if (item.type == '1') {
							return '<span class="label label-warning">按钮</span>';
						}
					}
				},
				{
					field : 'permission',
					title : '权限标识',
					width : '15%',
					align : "left",
					formatter : function(value, row, index) {
						return $.table.tooltip(value);
					}
				},
				{
					title : '操作',
					width : '20%',
					align : "left",
					formatter: function(value, row, index) {
		                var actions = [];		                
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.menuId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-danger btn-xs ' + deleteFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.menuId + '\')"><i class="fa fa-trash"></i>删除</a>');
		                return actions.join('');
		            }
				} ]
	};
	$.treeTable.init(options);
});